package com.simtop.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.simtop.common.ServerResponse;
import com.simtop.pojo.wddata.WdDate;
import com.simtop.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.annotation.HttpMethodConstraint;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;


@RestController
@RequestMapping("/api")
@CrossOrigin
public class ApiController {

    @Autowired
    private ApiService apiService;
    /*
    * 接收参数
    *
    * */
    @PostMapping("/rtdata")
    public void rtdata(@RequestBody String data, HttpServletRequest request) {
        //转发udp
        try {

            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            String createtime = df.format(new Date());
            //当前厂房信息
            String plant = "A6";
            apiService.saverapi(data, createtime, plant);
         } catch (Exception e) {
                e.printStackTrace();
            }
        }


    @PostMapping("/rtdatatest")
    public void rtdatatest(@RequestBody String data, HttpServletRequest request) {

            JSONObject jsonObject = JSON.parseObject(data);
            String rts = jsonObject.getString("rts");
            List<WdDate> lastDate = JSON.parseArray(rts, WdDate.class);
           //System.out.println(rts);

    }




    }




